//
//  RideHailingViewController.m
//  AppointmentForCar
//
//  Created by TheMacBook on 2016/11/15.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "RideHailingViewController.h"
#import "RideHailingModel.h"
#import "SuccessfulViewController.h"
@interface RideHailingViewController ()<SuccessfulViewControllerDelegate>

@end

@implementation RideHailingViewController
{
    UILabel * _rideingLabel;
    UILabel * _tipLabel;
    UIButton * _cancelButton;
    UIImageView * _imageView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    _rideingLabel = [[UILabel alloc] init];
    _tipLabel = [[UILabel alloc] init];
    _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"calling"]];
    _rideingLabel.text = @"正在为您呼叫车辆...";
    _tipLabel.text = @"请再稍等一下，马上有人接单！";
    [_cancelButton setTitle:@"取消呼叫" forState:UIControlStateNormal];
    _rideingLabel.textColor = [UIColor colorWithString:@"#EE7D00"];
    _rideingLabel.font = kAppFontSize(20);
    _tipLabel.textColor = [UIColor colorWithString:@"#868686"];
    _tipLabel.font = kAppFontSize(12);
    [_cancelButton setTitleColor:[UIColor colorWithString:@"#FE1E0C"] forState:UIControlStateNormal];
    _cancelButton.layer.cornerRadius = 20;
    _cancelButton.layer.borderWidth = 1;
    _cancelButton.layer.borderColor = [UIColor colorWithString:@"#E4E4E4"].CGColor;
    [_cancelButton addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    self.view.addSubview(_rideingLabel).addSubview(_tipLabel).addSubview(_cancelButton).addSubview(_imageView);
    [self layout];
    __weak __typeof__(self) weakSelf = self;
    [[PushManager sharePushManager] getCallPassengerInfo:^(CallCarModel *model) {
        // 司机抢单成功
        __strong __typeof__(weakSelf) strongSelf = weakSelf;
        SuccessfulViewController * controller = [[SuccessfulViewController alloc] init];
        controller.model = model;
        controller.delegate = strongSelf;
        [strongSelf presentViewController:controller animated:YES completion:nil];
    }];
}

- (void)layout
{
    __weak typeof(self) weakSelf = self;
    [_rideingLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.view);
        make.top.equalTo(weakSelf.view.mas_top).mas_offset(kScaleHeight(90));
        
    }];
    [_tipLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.view);
        make.bottom.equalTo(_cancelButton.mas_top).mas_offset(-kScaleHeight(30));
    }];
    [_cancelButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.view);
        make.bottom.equalTo(weakSelf.view.mas_bottom).mas_offset(-kScaleHeight(100));
        make.size.mas_equalTo((CGSize){kScaleWidth(140),kScaleHeight(44)});
    }];
    [_imageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(weakSelf.view);
        make.size.mas_equalTo((CGSize){kScaleHeight(130),kScaleHeight(130)});
    }];
}
- (void)clickCancel {
    if([_delegate respondsToSelector:@selector(rideHailingCancelOrder:)])
    {
        [_delegate rideHailingCancelOrder:self];
    }
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)successfulClick:(SuccessfulViewController *)controller {    
    [controller dismissViewControllerAnimated:NO completion:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.delegate successfulAction];
}
@end
